package com.leyou.item.mapper;

import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface BrandMapper extends Mapper<Brand>, SelectByIdListMapper<Brand,Long> {
    //新增 品牌和分类的中间表
    @Insert("insert into tb_category_brand values(#{cid},#{bid})")
    void insertCategoryandBrand(@Param("cid") Long cid, @Param("bid") Long bid);

    //修改 品牌和分类的中间表
    //@Update("update tb_category_brand set category_id = #{cid} where brand_id = #{bid}")
    @Insert("insert into tb_category_brand values(#{cid},#{bid})")
    void editCategoryandBrand(@Param("cid") Long cid, @Param("bid") Long bid);

    //删除中间表的相应信息
    @Delete("delete from tb_category_brand where brand_id = #{bid}")
    void delBrand(@Param("bid")Long bid);

    //新增商品时，查询所属分类的品牌信息
    @Select("select * from tb_brand where id in (select brand_id from tb_category_brand where category_id = #{cid})")
    List<Brand> queryBrandByCategory(@Param("cid") Long cid);



}
